import {getDictDataAPI} from "@/api/api.js"

export default {
	 data(){
	    return {
	        dictCode:{
	           
	        }
	    }
	  },
	  created(){
	    this.initDictlist()
	  },
	  methods:{
	    initDict(dict){
	        return new Promise((resolve, reject) => {
	          getDictDataAPI(dict).then(res => {
	            let result= res 
	            resolve(result)
	          })
	        })
	    }, 
	    initDictlist() {
	        if(Object.keys(this.dictCode).length == 0){
	            return
	        }
	        var keys=Object.keys(this.dictCode)
	        let list = keys.map(async (item, index) => {
	            this.dictCode[item]=await this.initDict(item)
	            return item
	        })
	        Promise.all(list).then((value,i) => {    
	            console.log('调用字典：',this.dictCode)
	        })
	      
	    },
	    formatDict(list,e) {
	        if (e || e==0) {
	            let obj = list.find((item) => {
	                return item.value == e
	            })
	            if (obj) {
	                return obj.label  
	            } else {
	                return e
	            }
	        } else {
	            return '未知'
	        }
	    },
	  }
};